﻿<Controls:MetroWindow xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"  x:Class="ChoWorkflowDashboard.ChoMainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        xmlns:local="clr-namespace:ChoWorkflowDashboard;assembly="
        xmlns:dm="clr-namespace:ChoWorkflowServer.Model;assembly=ChoWorkflowServer.Model"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"        
        xmlns:chrome="clr-namespace:Xceed.Wpf.Toolkit.Chromes;assembly=Xceed.Wpf.Toolkit"
        xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters;assembly=Xceed.Wpf.Toolkit"
        Title="Tasks Dashboard - Cinchoo Inc." Height="563" Width="900" MinHeight="400" MinWidth="500" Loaded="Window_Loaded" Icon="/ChoWorkflowDashboard;component/App.ico" Activated="Window_Activated"
        BorderBrush="{DynamicResource AccentColorBrush}"
        BorderThickness="1"
                      >
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ChoDataGridResource.xaml" />
                <ResourceDictionary Source="ChoTreeViewResource.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <!-- The view model that provides the data for the trees -->
            <!--<dm:TaskModel x:Key="Tasks" />-->
            <!--<CollectionViewSource x:Key="cvsTasks" />-->

            <!-- a custom root node for the tree -->
            <TreeViewItem x:Key="CustomRootNode">
                <TreeViewItem.Header>
                    <StackPanel Orientation="Horizontal"
                        Margin="0,2,0,2">
                        <Image x:Name="imgStatus"
                     Source="/Images/Home.png"
                     Width="16"
                     Height="16" />
                        <TextBlock Margin="2,0,0,0"
                         VerticalAlignment="Center"
                         FontWeight="Bold"
                         Text="All Tasks" />
                    </StackPanel>

                </TreeViewItem.Header>
            </TreeViewItem>
            <BooleanToVisibilityConverter x:Key="BoolToVisibility" />
        </ResourceDictionary>
    </Window.Resources>

    <Window.CommandBindings>
        <!-- bindings for context menu commands -->
        <CommandBinding Command="Redo"
                        CanExecute="EvaluateCanAddTaskGroup"
                    Executed="AddTaskGroup" />

        <CommandBinding Command="New"
                        CanExecute="EvaluateCanAddTask"
                    Executed="AddTask" />

        <CommandBinding Command="Delete"
                    CanExecute="EvaluateCanDelete"
                    Executed="DeleteCategory" />

        <CommandBinding Command="Open"
                    CanExecute="EvaluateCanEdit"
                    Executed="EditCategory" />

        <CommandBinding Command="Copy"
                    CanExecute="EvaluateCanCopy"
                    Executed="CopyCategory" />

        <CommandBinding Command="Paste"
                    CanExecute="EvaluateCanPaste"
                    Executed="PasteCategory" />

        <CommandBinding Command="Replace"
                    CanExecute="EvaluateCanMove"
                    Executed="MoveCategory" />

        <CommandBinding Command="Save"
                    CanExecute="EvaluateCanExport"
                    Executed="ExportCategory" />

        <CommandBinding Command="SaveAs"
                    CanExecute="EvaluateCanImport"
                    Executed="ImportCategory" />

    </Window.CommandBindings>

    <DockPanel>
        <StatusBar DockPanel.Dock="Bottom" Margin="2" >
            <TextBlock x:Name="txtStatus" FontStyle="Normal">
                Ready
            </TextBlock>
        </StatusBar>

        <Grid x:Name="MasterGrid" >
            <Grid.RowDefinitions>
                <RowDefinition Height="40" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="25*" MinWidth="100" />
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="75*" MinWidth="100" />
            </Grid.ColumnDefinitions>

            <Grid Grid.ColumnSpan="3" Grid.Row="0" Name="grdTitle" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="5*"/>
                </Grid.ColumnDefinitions>
                <!-- header area -->
                <TextBlock x:Name="Header" Margin="2"
                    FontStyle="Normal"
                    FontWeight="ExtraBold"
                    FontSize="18pt"
                    FontFamily="Verdana"
                    Grid.Column="0" Grid.Row="0" 
                    VerticalAlignment="Center" 
                        >
                    <TextBlock.BitmapEffect>
                        <OuterGlowBitmapEffect GlowColor="White" />
                    </TextBlock.BitmapEffect>
                    <TextBlock Text="TASKS DASHBOARD" Name="tblTitle" Margin="5,0,0,0" />
                </TextBlock>
                <StackPanel Grid.Column="1" Grid.Row="0" Margin="2" Orientation="Horizontal" FlowDirection="RightToLeft">
                    <StackPanel Grid.Column="1" Grid.Row="0" Margin="2" Orientation="Horizontal" FlowDirection="RightToLeft" Name="spOtherCmds">
                        <Button Content="Holiday Calendar" Name="btnHolidayCal" Height="25" Width="110" Margin="2" Click="btnHolidayCal_Click" BorderThickness="1" 
                        Visibility="{Binding Path=IsEditHolidayCalendarEnabled, Converter={StaticResource BoolToVisibility}}" IsEnabled="False" />
                        <Button Content="View Clusters" Name="btnViewClusters" Height="25" Width="110" Margin="2" Click="btnViewClusters_Click" BorderThickness="1" 
                        IsEnabled="True" />
                        <Button Content="Manage Users" Name="btnAdminUsers" Height="25" Width="110" Margin="2" Click="btnAdminUsers_Click" BorderThickness="1" 
                        Visibility="{Binding Path=IsManageUsersEnabled, Converter={StaticResource BoolToVisibility}}" IsEnabled="False" />
                        <Button Content="Manage Groups" Name="btnAdminRoles" Height="25" Width="110" Margin="2" Click="btnAdminRoles_Click" BorderThickness="1" 
                        Visibility="{Binding Path=IsManageUsersEnabled, Converter={StaticResource BoolToVisibility}}" IsEnabled="False" />
                    </StackPanel>
                    <Button Content="Refresh" Name="btnRefresh" Height="25" Width="110" Margin="2" Click="btnRefresh_Click" BorderThickness="1" />
                </StackPanel>
            </Grid>
            <Grid Grid.Row="1" Grid.Column="2" Name="grdContent" >
                <DataGrid Margin="2"
                  Name="dgTasks" 
                  EnableRowVirtualization="True" 
                  EnableColumnVirtualization="True" 
                  VirtualizingStackPanel.IsVirtualizing="True"
                  VirtualizingStackPanel.VirtualizationMode="Standard"
                  ItemsSource="{Binding TasksData}"
                  IsReadOnly="True" Grid.Row="1" Grid.Column="2"
                          ContextMenu="{StaticResource TasksActionMenu}"
                  AutoGeneratingColumn="dgTasks_AutoGeneratingColumn" 
                SelectedItem="{Binding SelectedRow, Mode=TwoWay}"
                CanUserSortColumns="True" SelectionChanged="dgTasks_SelectionChanged"
                          RowHeight="50"
                >
                </DataGrid>
            </Grid>
            <GridSplitter HorizontalAlignment="Right" 
                  VerticalAlignment="Stretch" 
                  Grid.Row="1" Grid.Column="1" ResizeBehavior="PreviousAndNext" Width="1" 
                  />
            <Grid Grid.Row="1" Grid.Column="0">
                <Grid HorizontalAlignment="Stretch" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" MinHeight="50" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" MinWidth="25" />
                        <ColumnDefinition Width="0.01*" />
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Row="0" HorizontalAlignment="Stretch" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="5*" MinHeight="150" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" MinHeight="50" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" MinWidth="25" />
                        </Grid.ColumnDefinitions>
                        <local:ChoTasksTree Grid.Row="0" Grid.Column="0" Margin="2" x:Name="TasksTree"
                          Items="{Binding Path=Tasks.Categories}"
                          NodeContextMenu="{StaticResource TasksMenu}"
                          TreeNodeStyle="{StaticResource SimpleFolders}"
                          TreeStyle="{StaticResource SimpleTreeStyle}"
                          SelectedItemChanged="OnSelectedItemChanged" >
                        </local:ChoTasksTree>
                        <GridSplitter HorizontalAlignment="Stretch" Height="1" 
                                  VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" ResizeBehavior="PreviousAndNext" />
                        <TextBox Grid.Row="2" Grid.Column="0" Margin="2" Name="txtTaskComments" IsReadOnly="True" 
                         IsReadOnlyCaretVisible="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto">
                            <TextBox.ToolTip>
                                <ToolTip Background="Aqua" Foreground="Black" />
                            </TextBox.ToolTip>
                        </TextBox>
                    </Grid>
                    <Button Grid.Row="1" Grid.Column="0" Content="Configure" Name="btnConfigure" Height="25" MinWidth="75" Margin="5,5,2,5" Click="btnConfigure_Click" BorderThickness="1" 
                        HorizontalAlignment="Stretch" />
                </Grid>
            </Grid>
        </Grid>
    </DockPanel>
</Controls:MetroWindow>
